package com.micai.springboot.redis.producer;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.listener.ChannelTopic;

/**
 * @Auther: zhaoxinguo
 * @Date: 2018/9/28 14:54
 * @Description: Redis消息生产者
 */
public class RedisCustomerInfoPublisher implements CustomerInfoPublisher {

    @Autowired
    private RedisTemplate<String, Object> redisTemplate;

    @Autowired
    private ChannelTopic topic;

    public RedisCustomerInfoPublisher() {
    }

    public RedisCustomerInfoPublisher(RedisTemplate<String, Object> redisTemplate, ChannelTopic topic) {
        this.redisTemplate = redisTemplate;
        this.topic = topic;
    }

    /**
     * 发送消息
     * @param message
     */
    @Override
    public void publish(String message) {
        redisTemplate.convertAndSend(topic.getTopic(), message);
    }
}
